# -*- coding: utf-8 -*-
import scrapy
from lxml import etree


class SmzdmSpider(scrapy.Spider):
    name = 'smzdm'
    allowed_domains = ['smzdm.com']
    start_urls = ["https://m.smzdm.com/youhui/p%s/" % i for i in range(1, 501)]

    def parse(self, response):
        html = response.body.decode()

        xhtml = etree.HTML(html)

        xlist = xhtml.xpath('//div[@class="main"]//ul/li')

        for x in xlist:
            yield {
                "title": x.xpath('.//div[@class="card-title"]/text()')[0].strip(),
                "price_info": x.xpath('.//div[@class="card-price"]/text()')[0].strip(),
                "laiyu": x.xpath('.//span[@class="card-mall"]/text()')[0].strip(),
                "time": x.xpath('.//div[@class="card-actions-left"]//span[2]/text()')[0].strip()
            }
